$(function(){

	function GetQueryString (name) { //获取指定name的url参数
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return (r[2]);
        return null;
    }
    function Toast (txt){
        var toastHtml = '<div class="tk_info" id="tkInfo"></div>';
        var toast = $('body #tkInfo');
        if (toast.length) {
            toast.html(txt).show();
        }else{
            $('body').append(toastHtml);
            $('body #tkInfo').html(txt).show();
        }
        setTimeout(function(){
          $('body #tkInfo').hide();
        },3000)
    }
    const host ='http://'+ GetQueryString('invokeDomain');
    const userId = GetQueryString('userId');
    const token = GetQueryString('token');


    //返回状态
    function state(key){
        var txt = '';
        switch(key) {
             case 0:
                txt = '待审核'
                break;
             case 1:
                 txt = '成功'
                break;
             default:
                txt = '驳回'
        };
        return txt
    }
    //获取数据
    function getData(){
    	$.ajax({
    		type:'get',
            dataType: 'json',
            url:host+'/system/api/transfer/logs',
            data: {
            	'userId':userId,
            	'token':token
            },
            //请求成功时执行
            success: function(v) {
                const code = v.code;
                const msg = v.msg;
                const data = v.data;
                if (code == 0) {
                	if (!data||data.length == 0) {
                        $('.haveData').hide()
                        $('.noData').show()
                    }else{
                        var html = [];
                        data.forEach(function(item,index){
                            var states = state(item.state);
                            var liHtml = '<li>'+
                                        '   <div class="top">'+
                                        '        <div class="left">'+
                                        '           <h3>'+item.channel+'提现'+states+'</h3>'+
                                        '            <p>消耗红包券  '+item.money+'</p>'+
                                        '        </div>'+
                                        '        <span class="right">￥'+item.txMoney+'元</span>'+
                                        '    </div>'+
                                        '    <a href="withdraw-detail.html?userId='+userId+'&token='+token+'&id='+item.id+'&invokeDomain='+GetQueryString('invokeDomain')+'" class="buttom">'+
                                        '        <p>'+item.createTime+'</p>'+
                                        '        <span>查看详情</span>'+
                                        '    </a>'+
                                        '</li>';
                            html.push(liHtml)
                        });
                        $('.list').html(html.join(' '))
                    }
                } else {
                    // 异常处理
                    console.log('去登录');
                    
                }
            },
            //请求失败遇到异常触发
            error: function(d) {
                console.log(d.msg);
                
            }
    	})
    }

    getData()

})